Completed
Push — master ( b8a2ae...421529 )
by Samson
02:36
created

GeezifyTest.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 14
rs 9.95
c 0
b 0
f 0
1
const assert = require('assert');
2
3
const sinon = require('sinon');
4
5
const Geezify = require('../src/Geezify');
6
const GeezConverter = require('../src/Converter/GeezConverter');
7
const AsciiConverter = require('../src/Converter/AsciiConverter');
8
9
/* global describe, it */
10
11
describe('GeezifyTest', () => {
12
  describe('#test_random_numbers()', () => {
13
    it('should convert random ascii number to geez and back to the original', () => {
14
      const $geezify = Geezify.create();
15
16
      for (let $i = 0; $i < 10000; $i += 1) {
17
        const $random_number = Math.floor(Math.random() * 9999999999);
18
19
        const $geez_number = $geezify.toGeez($random_number);
20
        const $ascii_number = $geezify.toAscii($geez_number);
21
22
        assert.equal($random_number, $ascii_number);
23
      }
24
    });
25
  });
26
27
  describe('#test_geezify_build_process()', () => {
28
    it('should use provided ascii and geez number converters', () => {
29
      const $geez = new GeezConverter();
30
      const $ascii = new AsciiConverter();
31
32
      sinon
33
        .stub($geez, 'convert')
34
        .withArgs(123)
35
        .returns('giber gaber');
36
      sinon
37
        .stub($ascii, 'convert')
38
        .withArgs('lorem ipsum')
39
        .returns(321);
40
41
      const $geezify = new Geezify($geez, $ascii);
42
43
      // assert the response
44
      assert.equal(321, $geezify.toAscii('lorem ipsum'));
45
      assert.equal('giber gaber', $geezify.toGeez(123));
46
    });
47
  });
48
49
  describe('#test_setter_and_getters()', () => {
50
    it('should be able to substitute implementations', () => {
51
      const $geezify = Geezify.create();
52
53
      const $geez_dummy = sinon.createStubInstance(GeezConverter);
54
      const $ascii_dummy = sinon.createStubInstance(AsciiConverter);
55
56
      $geezify.setGeezConverter($geez_dummy);
57
      $geezify.setAsciiConverter($ascii_dummy);
58
59
      assert.equal($geez_dummy, $geezify.getGeezConverter());
60
      assert.equal($ascii_dummy, $geezify.getAsciiConverter());
61
    });
62
  });
63
});
64